#include <stdio.h>
#include <stdarg.h>

#include "Log.h"

namespace Log
{
	static FILE *logFile = NULL;
	
	bool init(const char *filename)
	{
		logFile = fopen(filename ? filename : "app.log", "w");
		return true;
	}
	
	void free()
	{
		if (logFile)
			fclose(logFile);
	}
	
	void write(const char *format, ...)
	{
		if (!logFile)
			return;
		
		va_list ap;
		va_start(ap, format);
		vfprintf(logFile, format, ap);
		va_end(ap);
		
		fflush(logFile);
	}
}
